package com.usian.admin.controller.v1;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: AdChannelController
 * Author:   WGG
 * Date:    2022-11-2022/11/9-16:27
 * Version: 1.0
 * Description:
 */

/**
 *频道管理的controller
 */
@RestController
@RequestMapping("/admin/api/v1/channel")
@Api(value = "频道管理",tags = "channel",description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;

    /**
     * 根据name查询对应的channel数据
     * @param channelDto
     * @return
     */

    @Override
    @PostMapping("list")
    @ApiOperation(value = "查询频道信息",notes = "分页查询")
    @ApiImplicitParam(name = "channelDto",type = "ChannelDto",value = "查询参数")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return adChannelService.findByNameAndPage(channelDto);
    }

    /**
     * 新增频道
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("save")
    @ApiOperation(value = "新增频道",notes = "新增")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "添加参数")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return adChannelService.saveChannel(adChannel);
    }

    /**
     * 根据id修改频道
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("update")
    @ApiOperation(value = "编辑频道",notes = "编辑")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "修改参数")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.updateChannel(adChannel);
    }


    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Override
    @GetMapping("del/{id}")
    @ApiOperation(value = "删除频道",notes = "根据id删除")
    @ApiImplicitParam(name = "id",type = "Integer",value = "删除参数")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }

    @Override
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }


}
